package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.EquityDataDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.EquityData;
import sanrenxing.dayEnd.backRepertoryTotal.domain.EquityDataT;
import sanrenxing.dayEnd.backRepertoryTotal.service.EquityDataService;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @desrciption 权益数据 业务处理
 * @auth：yidu 李小锋
 * @date:2021/3/13 0013 - 11:39
 * @version:1:0
 */
@Service("/EquityDataService")
public class EquityDataServiceImpl implements EquityDataService {
    //自动装配
    @Autowired
    private EquityDataDao equityDataDao;
    /**
     * 新增一行数据
     *
     * @param equityData 对象
     * @return 0、增加失败 1、增加成功
     */
    @Override
    public int add(EquityData equityData) {
        return equityDataDao.add(equityData);
    }

    /**
     * 删除一行数据
     *
     * @param rightsId 编号
     * @return 0、删除失败 1、删除成功
     */
    @Override
    public int delete(int rightsId) {
        return equityDataDao.delete(rightsId);
    }

    /**
     * 修改一行数据
     *
     * @param equityData 对象
     * @return 0、修改失败 1、修改成功
     */
    @Override
    public int update(EquityData equityData) {
        return equityDataDao.update(equityData);
    }

    /**
     * 查询所有的订单数据
     *
     * @return 返回一个订单集合
     */
    @Override
    public List<EquityData> findAll() {
        return equityDataDao.findAll();
    }

    /**
     * 分页查询
     *
     * @param start     开始行号
     * @param rows      每页行数
     * @param condition 查询条件
     * @return 集合
     */
    @Override
    public List<EquityData> findByPage(int start, int rows, String condition) {
        int pages=((rows-1)*start)+1;
        //int star=rows*start+1;
        return equityDataDao.findByPage(pages,pages+start,condition);
    }

    /**
     * 按条件统计出记录行数
     *
     * @param condition 条件
     * @return 记录行数
     */
    @Override
    public int count(String condition) {
        return equityDataDao.count(condition);
    }

    /**
     * 获取查询条件
     *
     * @param equityData 对象
     * @return 条件字符串
     */
    @Override
    public String getcondition(EquityData equityData) {
        String condition=" ";
        if(equityData==null){
            return condition;
        }

        //rightsId	权益id	int
        if(equityData.getRightsId()!=0){
            condition+="and rightsId '%"+equityData.getRightsId()+"%'";
        }
        //seId	证券id	varchar2
        if (equityData.getSeId()!=null && equityData.getSeId().trim().length()!=0){
            condition+="and seId like '%"+equityData.getSeId()+"%'";
        }
        //rigDay	权益登记日	date
        if(equityData.getRigDay()!=null ){
            condition+="and rigDay"+equityData.getRighDay()+"";
        }
        //righDay	权益除权日	date
        if(equityData.getRighDay()!=null ){
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
            condition+="and righDay like to_date('"+sdf.format(equityData.getRighDay())+"','yyyy-MM-dd')";
        }
        //dueDate	到账日期	date
        if(equityData.getDueDate()!=null ){
            condition+="and dueDate '%"+equityData.getDueDate()+"%'";
        }
        //rigType	权益类型	varchar2
        if (equityData.getRigType()!=null && equityData.getRigType().trim().length()!=0){
            condition+="and rigType in ("+equityData.getRigType()+")";
        }
        //pro	比例%	varchar2
        if (equityData.getPro()!=null && equityData.getPro().trim().length()!=0){
            condition+="and pro like '%"+equityData.getPro()+"%'";
        }
        //proState	处理状态（1未处理 2：已处理）	varchar2
        if (equityData.getProState()!=null && equityData.getProState().trim().length()!=0){
            condition+="and proState like '%to_date("+equityData.getProState()+",'yyyy-MM-dd')%'";
        }
        //businDate	业务日期	date
        if(equityData.getBusinDate()!=null ){
            condition+="and businDate '%"+equityData.getBusinDate()+"%'";
        }
        return condition;
    }

    @Override
    public void addExcl(EquityDataT equityDataT) {
        equityDataDao.addExcl(equityDataT);
    }
}
